package com.qf.flash.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.qf.flash.app.MyApp;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXImageObject;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;

import java.io.File;

public class ShareUtils {

    public static void imageShare(String imgPath, int sendtype) {

        File file = new File(imgPath);
        if (!file.exists()) {
           AppToast.showToast("图片不存在");
        }

        WXImageObject imgObj = new WXImageObject();

        imgObj.setImagePath(imgPath);
        WXMediaMessage msg = new WXMediaMessage();
        msg.mediaObject = imgObj;
        Bitmap bmp = BitmapFactory.decodeFile(imgPath);
        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 100, 100, true);
        msg.setThumbImage(thumbBmp);
        bmp.recycle();
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = msg;
        req.scene = sendtype == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
        MyApp.mWxApi.sendReq(req);
    }



}
